Skip to content

[DX] Support multi-mip Texture2D SRVs (#1039)#1230

Draft
alsepkow wants to merge 10 commits into
llvm:mainfrom
alsepkow:alex/dx-mips-1039
Draft

[DX] Support multi-mip Texture2D SRVs (#1039)#1230
alsepkow wants to merge 10 commits into
llvm:mainfrom
alsepkow:alex/dx-mips-1039

Conversation

@alsepkow

@alsepkow alsepkow commented May 27, 2026

Copy link
Copy Markdown
Collaborator

EXPERIMENTAL - NOT FOR REVIEW

AI-assisted exploration driving design discussion for llvm/wg-hlsl#400. Not intended for review/merge in current form.

Adds D3D12 support for multi-mip Texture2D SRVs, matching the existing Vulkan implementation. Tests can now declare a Texture2D with a populated mip chain and verify per-mip Load reads.

Pipeline schema gains OutputProperties.MipLevels and Resource.MostDetailedMip / Resource.MipLevels for the SRV view. The DX backend allocates the full mip chain via D3D12_RESOURCE_DESC::MipLevels, drives per-mip uploads through GetCopyableFootprints for the right row-pitch alignment, and configures the SRV with MostDetailedMip + MipLevels from the YAML.

Tests: Texture2D.Load.Mips.test exercises per-mip loads across 3 mip levels. PASS on d3d12, warp-d3d12, vk (VK was already supported).

Resolves #1039


Assisted by Claude Opus 4.7.

alsepkow and others added 4 commits May 26, 2026 17:52
Lifts the early-return guard on MipLevels > 1 for SRV textures and threads the mip count through to the D3D12_RESOURCE_DESC and the SRV's MipLevels field.

Adds a per-mip upload path using GetCopyableFootprints so each subresource is copied with the correct D3D12_TEXTURE_DATA_PITCH_ALIGNMENT row pitch. The single-mip path is unchanged.

RWTexture2D mips are still rejected with not_supported (no per-mip UAV support yet).

Adds a new Texture2D.Load.MipMaps.test.yaml covering the 4x4 + 3-mip layout documented in docs/MipMappedTextures.md. Re-enables Texture2D.mips.OperatorIndex / Texture2D.OperatorIndex / Texture2D.GetDimensions on dxc-d3d12 and dxc-warp-d3d12 by qualifying the XFAIL to 'Clang && DirectX' for the unrelated Clang-DX path tracked in llvm/llvm-project#101558.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses code review feedback on the multi-mip support change: the
relaxed guard (changed from `!= 1` to `> 1 && !SRV`) silently
accepted MipLevels values of 0 or negative integers. Since
OutputProps.MipLevels is signed int, 0 would cast to a UINT(0) in the
SRV desc (which D3D12 interprets as the magic "use all mip levels"
value) and negative values would wrap to a huge uint16_t in the
RESOURCE_DESC. Add an explicit lower-bound check so invalid input is
rejected with a clear error instead of silently producing surprising
behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply clang-format 19.1.6 to changed regions per pr-code-format CI.
Picks up the DriverVer fix (upstream llvm#1228) so clang-tidy stops failing on Device.cpp.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
alsepkow and others added 2 commits May 27, 2026 13:29
Fixes misc-const-correctness warnings-as-errors from clang-tidy in CI.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
alsepkow and others added 4 commits June 4, 2026 17:48
Skips non-texture resources where MipLevels is ignored downstream.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DirectX] Add multiple mip level support

1 participant